package com.dao.impl;

import com.bean.User;
import com.dao.UsersDao;
import com.utils.DruidUtil;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class UsersDaoImpl implements UsersDao {
    public static final JdbcTemplate JDBC_TEMPLATE = new JdbcTemplate(DruidUtil.getDataSource());
    @Override
    public User login(String name, String pwd) {
        String sql = "select * from user where uname = ? and upwd = ?";
        List<User> users = JDBC_TEMPLATE.query(sql, new BeanPropertyRowMapper<>(User.class), name, pwd);
        return users.size()==1?users.get(0):null;
    }
}
